home *** CD-ROM | disk | FTP | other *** search
/ Chip: Internet / Chip Internet.iso / viewer / sox7dos / st.man < prev    next >
Text File  |  1993-02-11  |  6KB  |  195 lines

  1. .de Sh
  2. .br
  3. .ne 5
  4. .PP
  5. \fB\\$1\fR
  6. .PP
  7. ..
  8. .de Sp
  9. .if t .sp .5v
  10. .if n .sp
  11. ..
  12. .TH ST 1
  13. .SH NAME
  14. st - Sound Tools - sound sample file and effects libraries.
  15. .SH SYNOPSIS
  16. .B cc \fIfile.c\fB -o \fIfile \fBlibst.a
  17. .SH DESCRIPTION
  18. .I Sound\ Tools
  19. is a library of sound sample file format readers/writers
  20. and sound effects processors.
  21. .P
  22. Sound Tools includes skeleton C
  23. files to assist you in writing new formats and effects.  
  24. The full skeleton driver, skel.c, helps you write drivers 
  25. for a new format which has data structures.  
  26. The simple skeleton drivers
  27. help you write a new driver for raw (headerless) formats, or
  28. for formats which just have a simple header followed by raw data.
  29. .P
  30. Most sound sample formats are fairly simple: they are just a string
  31. of bytes or words and are presumed to be sampled at a known data rate.
  32. Most of them have a short data structure at the beginning of the file.
  33. .SH INTERNALS
  34. The Sound Tools formats and effects operate on an internal buffer format
  35. of signed 32-bit longs.
  36. The data processing routines are called with buffers of these
  37. samples, and buffer sizes which refer to the number of samples
  38. processed, not the number of bytes.
  39. File readers translate the input samples to signed longs
  40. and return the number of longs read.
  41. For example, data in linear signed byte format is left-shifted 24 bits.
  42. .P
  43. This does cause problems in processing the data.  
  44. For example:
  45. .br
  46.     *obuf++ = (*ibuf++ * *ibuf++)/2;
  47. .br
  48. would
  49. .I not
  50. mix down left and right channels into one monophonic channel,
  51. because the resulting samples would overflow 32 bits.
  52. Instead, the ``avg'' effects must use:
  53. .br
  54.     *obuf++ = *ibuf++/2 * *ibuf++/2;
  55. .br
  56. .P
  57. Stereo data is stored with the left and right speaker data in
  58. successive samples.
  59. Quadraphonic data is stored in this order: 
  60. left front, right front, left rear, right rear.
  61. .SH FORMATS
  62. .I format 
  63. is responsible for translating between sound sample files
  64. and an internal buffer.  The internal buffer is store in signed longs
  65. with a fixed sampling rate.  The 
  66. .I format
  67. operates from two data structures:
  68. a format structure, and a private structure.
  69. .P
  70. The format structure contains a list of control parameters for
  71. the sample: sampling rate, data size (bytes, words, floats, etc.),
  72. style (unsigned, signed, logarithmic), number of sound channels.
  73. It also contains other state information: whether the sample file
  74. needs to be byte-swapped, whether fseek() will work, its suffix,
  75. its file stream pointer, its 
  76. .I format
  77. pointer, and the 
  78. .I private
  79. structure for the 
  80. .I format .
  81. .P
  82. The 
  83. .I private 
  84. area is just a preallocated data array for the 
  85. .I format
  86. to use however it wishes.  
  87. It should have a defined data structure
  88. and cast the array to that structure.  
  89. See voc.c for the use of a private data area.  
  90. Voc.c has to track the number of samples it 
  91. writes and when finishing, seek back to the beginning of the file
  92. and write it out.
  93. The private area is not very large.
  94. The ``echo'' effect has to malloc() a much larger area for its
  95. delay line buffers.
  96. .P
  97. .I format
  98. has 6 routines:
  99. .TP 20
  100. startread
  101. Set up the format parameters, or read in
  102. a data header, or do what needs to be done.
  103. .TP 20
  104. read
  105. Given a buffer and a length: 
  106. read up to that many samples, 
  107. transform them into signed long integers,
  108. and copy them into the buffer.
  109. Return the number of samples actually read.
  110. .TP 20
  111. stopread
  112. Do what needs to be done.
  113. .TP 20
  114. startwrite
  115. Set up the format parameters, or write out 
  116. a data header, or do what needs to be done.
  117. .TP 20
  118. write
  119. Given a buffer and a length: 
  120. copy that many samples out of the buffer,
  121. convert them from signed longs to the appropriate
  122. data, and write them to the file.
  123. If it can't write out all the samples,
  124. fail.
  125. .TP 20
  126. stopwrite
  127. Fix up any file header, or do what needs to be done.
  128. .SH EFFECTS
  129. An effects loop has one input and one output stream.
  130. It has 5 routines.
  131. .TP 20
  132. getopts
  133. is called with a character string argument list for the effect.
  134. .TP 20
  135. start
  136. is called with the signal parameters for the input and output
  137. streams.
  138. .TP 20 
  139. flow
  140. is called with input and output data buffers,
  141. and (by reference) the input and output data sizes.
  142. It processes the input buffer into the output buffer,
  143. and sets the size variables to the numbers of samples
  144. actually processed.
  145. It is under no obligation to fill the output buffer.
  146. .TP 20 
  147. drain
  148. is called after there are no more input data samples.
  149. If the effect wishes to generate more data samples
  150. it copies the generated data into a given buffer
  151. and returns the number of samples generated.
  152. If it fills the buffer, it will be called again, etc.
  153. The echo effect uses this to fade away.
  154. .TP 20
  155. stop
  156. is called when there are no more input samples to process.
  157. .I stop
  158. may generate output samples on its own.
  159. See echo.c for how to do this, 
  160. and see that what it does is absolutely bogus.
  161. .SH COMMENTS
  162. Theoretically, formats can be used to manipulate several files 
  163. inside one program.  Multi-sample files, for example the download
  164. for a sampling keyboard, can be handled cleanly with this feature.
  165. .SH PORTABILITY PROBLEMS
  166. Many computers don't supply arithmetic shifting, so do multiplies
  167. and divides instead of << and >>.  The compiler will do the right
  168. thing if the CPU supplies arithmetic shifting.
  169. .P
  170. Do all arithmetic conversions one stage at a time.
  171. I've had too many problems with "obviously clean" combinations.
  172. .P
  173. In general, don't worry about "efficiency".  
  174. The sox.c base translator
  175. is disk-bound on any machine (other than a 8088 PC with an SMD disk 
  176. controller).  
  177. Just comment your code and make sure it's clean and simple.
  178. You'll find that DSP code is extremely painful to write as it is.
  179. .SH BUGS
  180. The HCOM format is not re-entrant; it can only be used once in a program.
  181. .P
  182. The program/library interface is pretty weak.
  183. There's too much ad-hoc information which a program is supposed to
  184. gather up.
  185. Sound Tools wants to be an object-oriented dataflow architecture.
  186. .P
  187. The human ear can't really hear better than 20 bits.
  188. With an internal format of 16 bits, we will eventually
  189. destroy information when used to mix CD's.
  190. The internal format should be 24-bit signed data.
  191. But, with 24 bits you still have to be careful multiplying.
  192. Check the ``vibro'' effect for how it handles this problem.
  193.